<?php

class Jf_Tree_Href_Uri extends Jf_Tree_Node {

    protected $_uri = null;

    public function setUri ($uri) {
        if (null !== $uri &&  ! is_string ($uri)) {
            throw new Jf_Tree_Exception ('Invalid argument: $uri must be a string or null');
        }
        $this -> _uri = $uri;
        return $this;
    }

    public function getUri () {
        return $this -> _uri;
    }

    public function getHref () {
        $uri = $this -> getUri ();
        $fragment = $this -> getFragment ();
        if (null !== $fragment) {
            if ('#' == substr ($uri,  - 1)) {
                return $uri . $fragment;
            } else {
                return $uri . '#' . $fragment;
            }
        }
        return $uri;
    }

    public function toArray () {
        return array_merge (parent::toArray (), array('uri' => $this -> getUri ()));
    }

}
